package zhang.lao.console.controller.wn;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import zhang.lao.annotation.RepeatSubmit;
import zhang.lao.pojo.console.ConsoleContext;
import zhang.lao.pojo.console.req.BootStrapGridReq;
import zhang.lao.pojo.console.resp.BootStrapGridResp;
import zhang.lao.pojo.console.resp.HttpResult;
import zhang.lao.service.console.base.WnMachineDeviceService;
import javax.annotation.Resource;
import java.io.Console;

/**
* 农机设备装置
* @author ZhangQin
* @create 2017年08月28日 17:02
**/
@Controller
public class WnMachineDeviceController{
	@Resource
	private WnMachineDeviceService wnMachineDeviceService;

	@RequestMapping("/console/wn_machine_device/add")
	@RepeatSubmit(isAdd = true)
	public String add(){
		return wnMachineDeviceService.add();
	}

	@RepeatSubmit(isAdd = true)
	@RequestMapping("/console/wn_machine_device/edit")
	public String edit(ModelMap modelMap,Integer id){
		return  wnMachineDeviceService.edit(modelMap,id);
	}

	@RequestMapping("/console/wn_machine_device/addandlink/{machineId}")
	@RepeatSubmit(isAdd = true)
	public String addBymachineId(@PathVariable String machineId, ModelMap modelMap){
		modelMap.put(machineId,"machineId");
		return wnMachineDeviceService.add();
	}
	@RequestMapping("/console/wn_machine_device/list")
	public String list(){
		return  wnMachineDeviceService.list();
	}

	@RequestMapping("/console/wn_machine_device/json")
	public @ResponseBody BootStrapGridResp json(BootStrapGridReq bootGridReq, ConsoleContext consoleContext){
		return wnMachineDeviceService.json(bootGridReq,consoleContext);
	}

	@RepeatSubmit(isAdd = false)
	@RequestMapping("/console/wn_machine_device/save")
	public @ResponseBody HttpResult save(String formObjectJson, String machineId, ConsoleContext consoleContext){
		return wnMachineDeviceService.save(formObjectJson,machineId,consoleContext);

	}

	@RequestMapping("/console/wn_machine_device/delete")
	public @ResponseBody HttpResult delete(String ids){
        return wnMachineDeviceService.delete(ids);
	}
}
